//
//  AppDelegate+AppService.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/8.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "AppDelegate+AppService.h"

@implementation AppDelegate (AppService)

-(void)initWindow{
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    self.mainTabBar = [MainTabBarViewController new];
    self.window.rootViewController = self.mainTabBar;
    [self.window makeKeyAndVisible];
    [[UITabBar appearance] setTranslucent:NO];
    [[UIButton appearance] setExclusiveTouch:YES];
    [UIActivityIndicatorView appearanceWhenContainedInInstancesOfClasses:@[[UIView class]]];
    if (@available(iOS 11.0, *)){
        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
    }
}

-(void)initService{
    //键盘设置
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager]; // 获取类库的单例变量
    keyboardManager.enable = YES; // 控制整个功能是否启用
    keyboardManager.shouldResignOnTouchOutside = YES; // 控制点击背景是否收起键盘
    keyboardManager.shouldToolbarUsesTextFieldTintColor = YES; // 控制键盘上的工具条文字颜色是否用户自定义
    keyboardManager.toolbarManageBehaviour = IQAutoToolbarBySubviews; // 有多个输入框时，可以通过点击Toolbar 上的“前一个”“后一个”按钮来实现移动到不同的输入框
    keyboardManager.enableAutoToolbar = NO; // 控制是否显示键盘上的工具条
    keyboardManager.keyboardDistanceFromTextField = 10.0f; // 输入框距离键盘的距离
//    textField.inputAccessoryView = [[UIView alloc] init];
}

-(void)addNotification{
    //注册登录状态监听
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(roleStateChange:)
                                                 name:KNotificationRoleStateChange
                                               object:nil];
    
    //网络状态监听
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(netWorkStateChange:)
                                                 name:KNotificationNetWorkStateChange
                                               object:nil];
}
- (void)roleStateChange:(NSNotification *)notification{
    self.mainTabBar = nil;
    self.mainTabBar = [MainTabBarViewController new];
    [UIView transitionWithView:[UIApplication sharedApplication].keyWindow
                      duration:0.75f
                       options:UIViewAnimationOptionTransitionFlipFromRight
                    animations:^{
                        self.window.rootViewController = self.mainTabBar;
                    }
                    completion:nil];
    
//    CATransition *anima = [CATransition animation];
//    anima.type = @"cube";//设置动画的类型
//    anima.subtype = kCATransitionFromRight; //设置动画的方向
//    anima.duration = 0.3f;
//    self.window.rootViewController = self.mainTabBar;
//    [kAppWindow.layer addAnimation:anima forKey:@"revealAnimation"];
}
- (void)netWorkStateChange:(NSNotification *)notification{
    
}
@end
